package top.mcwebsite.playandroid.common.uiWidget

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties


@Composable
fun CustomDialog(
    onDismissRequest: () -> Unit,
    content: @Composable () -> Unit,
) {
    Dialog(
        properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
        onDismissRequest = {
            onDismissRequest()
        }
    ) {
        Box(
            contentAlignment = Alignment.Center,
            modifier = Modifier
                .background(color = Color.Black.copy(alpha = 0.2f))
                .fillMaxWidth()
                .fillMaxHeight()
                .clickable(indication = null, interactionSource = remember {
                    MutableInteractionSource()
                }) {
                    onDismissRequest()
                }
        ) {
            Box(modifier = Modifier.clickable(enabled = false) { }) {
                content()
            }
        }
    }
}